package com.xiaoyg.algorithm;

public class MoveZeros {
    public static void main(String[] args) {
        int [] array = {1,0,0,3,12};
        moveZeros(array);
        for (int i:array){
            System.out.printf(""+i);
        }
    }

    public static void moveZeros(int [] nums){
        int slow = 0;
        int fast = 0;
        while (fast < nums.length){
            //当快指针位置不为0,就将快指针的非0值赋值给慢指针的值。
            if (nums[fast] != 0){
                nums[slow] = nums[fast];
                slow ++;
            }
            fast++;
        }
        for (int i = slow; i < nums.length; i++) {
             nums[i] = 0;
        }
    }
}
